package com.tensquare.article.controller;

import com.tensquare.article.pojo.Comment;
import com.tensquare.article.service.CommentService;
import com.tensquare.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;
import java.util.List;

/**
 * @author BAO
 * @version V1.0
 * @Package com.tensquare.article.controller
 * @date 2020/12/3 19:32
 * @description:
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/findById/{id}")
    public Result findById(@PathVariable("id") String id){
        Comment comment = commentService.findById(id);
        return Result.success("mongo success",comment);
    }

    @GetMapping("/findAll")
    public  Result findAll(){
        Page<Comment> page = commentService.findAll();
        return Result.success("mongo success",page);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Comment comment){
        Comment save = commentService.save(comment);
        return Result.success("mongo success",save);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Comment comment){
        Comment update = commentService.update(comment);
        return Result.success("mongo success",update);
    }

    @DeleteMapping("/delete/{id}")
    public  Result deleteById(@PathVariable("id") String id){
        commentService.deleteById(id);
        return Result.success("mongo success",null);
    }

    @GetMapping("/Articleid/{id}")
    public Result findByArticleid(@PathVariable("id") String Articleid){
        List<Comment> list = commentService.findByarticleId(Articleid);
        return  Result.success("mongo success",list);
    }

    @GetMapping("/thumbup/{id}")
    public  Result getThumbup(@PathVariable("id") String id){
        commentService.getThumbup(id);
        return Result.success("mongo success",null);
    }

}
